package com.gitee.wsl.common.chart.render.background.quadrant

import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint

/**
 * @ClassName PlotQuadrant
 * @Description 四象限基类
 * @author XiongChuanLiang<br/>(xcl_168@aliyun.com)
 *
 */
class Quadrant() {
     var firstColor = Color.WHITE
     var secondColor = Color.WHITE
     var thirdColor = Color.WHITE
     var fourthColor = Color.WHITE

     var isVisible = false

     var isShowBgColor = true
     var isShowVerticalLine = true
     var isShowHorizontalLine = true

     val bgColorPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
     val verticalLinePaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)
     val horizontalLinePaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)

     var quadrantXValue = 0.0f
     var quadrantYValue = 0.0f

    /**
     * 显示象限
     * @param xValue    x轴值
     * @param yValue    y轴值
     */
    fun show(xValue: Float, yValue: Float) {
        setQuadrantXYValue(xValue, yValue)
        isVisible = true
    }

    /**
     * 设置象限中心点的值
     * @param xValue    x方向实际值
     * @param yValue    y方向实际值
     */
    fun setQuadrantXYValue(xValue: Float, yValue: Float) {
        quadrantXValue = xValue
        quadrantYValue = yValue
    }


    /**
     * 设置各个象限的颜色
     * @param first        第一象限
     * @param second    第二象限
     * @param third        第三象限
     * @param fourth    第四象限
     */
    fun setBgColor(first: Int, second: Int, third: Int, fourth: Int) {
        firstColor = first
        secondColor = second
        thirdColor = third
        fourthColor = fourth
    }

    fun renderQuadrant(
        canvas: Canvas,
        centerX: Float, centerY: Float,
        left: Float, top: Float, right: Float, bottom: Float
    ) {
        if (isShowBgColor){ //绘制bg
            bgColorPaint.color = firstColor
            canvas.drawRect(centerX, top, right, centerY, bgColorPaint)
            bgColorPaint.color = secondColor
            canvas.drawRect(centerX, centerY, right, bottom, bgColorPaint)
            bgColorPaint.color = thirdColor
            canvas.drawRect(left, centerY, centerX, bottom, bgColorPaint)
            bgColorPaint.color = fourthColor
            canvas.drawRect(left, top, centerX, centerY, bgColorPaint)
        }
        if (isShowVerticalLine) {
            canvas.drawLine(centerX, top, centerX, bottom, verticalLinePaint)
        }
        if (isShowHorizontalLine) {
            canvas.drawLine(left, centerY, right, centerY, horizontalLinePaint)
        }
    }
}